package com.xma.springcloud.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: arthur
 * @License: (C) Copyright 2020-2028, xxx Corporation Limited.
 * @Contact: 413911174@qq.com
 * @Date: 2020/7/4 17:37
 * @Version: 1.0
 * @Description:
 */
@RestController
@Slf4j
public class FlowLimitController {

    @GetMapping("/testA")
    public String testA(){

        return "--------------A";
    }
    @GetMapping("/testB")
    public String testB(){
        log.info(Thread.currentThread().getName() +"\t" +".....testB");
        return "--------------B";
    }

    @GetMapping("/testD")
    public String testD(){
        /*try {
            TimeUnit.SECONDS.sleep(1);
        }catch (Exception e){
            e.printStackTrace();
        }*/
        int i = 10 /0;
        log.info(Thread.currentThread().getName() +"\t" +".....testD");
        return "--------------testD";
    }

    /**
     * 降级处理
     */
    @GetMapping("/testHotKey")
    @SentinelResource(value = "testHotKey",blockHandler = "deal_testHotkey")
    public String testHotKey(@RequestParam(value = "p1",required = false) String p1,
                             @RequestParam(value = "p2",required = false) String p2){
        return "-----------testHotKey";
    }

    public String deal_testHotkey(String p1, String p2, BlockException exception){
        return "-----------deal_testHotKey, 😭";
    }

}
